<template>
  <div class="page">
    <!-- 表单 -->

    <a-card>
      <ComVxeTable
        :columns="columns"
        :axios="page"
        :fromItem="fromItem"
        :formData="formData"
        :initialize="initialize"
        @check-view="checkView"
        ref="table"
      >
        <template #button="data">
          <vxe-button content="导出数据" @click="download(data)"></vxe-button>
        </template>
      </ComVxeTable>
    </a-card>
    <flow-every-modal ref="modal" :state="false" :ajax="ajax">
      <!-- v-if="records.visbled" -->
      <template #default="records">
        <flow-check-table
          v-if="records.visbled"
          :sqsx="records.sqsx"
          :cyxpjl="records.cyxpjlList"
          :job="records.job"
          :sqsxid="records.sqsxid"
          :change="records.change"
          :nextNodeDbrList="records.nextNodeDbrList"
          :nextNode="records.nextNode"
        ></flow-check-table>
      </template>
      <template #footer>
        <div></div>
      </template>
    </flow-every-modal>
  </div>
</template>

<script>
// 药品器械统计
import flowEveryModal from "../components/stayflow/stayflow-every-modal.vue";
import {
  queryRckpStatPageList,
  exportRckpJbxxDatas,
  queryRckpStatJbxx,
} from "../api/dayPort";
import flowCheckTable from "@/views/everydayCheck/components/stayflow/stayflow-check-table";
import ComVxeTable from "../components/vxe-table/com-vxe-table.vue";
export default {
  props: ["type"],
  components: { ComVxeTable, flowEveryModal, flowCheckTable },
  name: "LoadPage",

  data() {
    return {
      columns: [
        {
          type: "checkbox",
          width:'60'
        },
        {
          type: "seq",
          title: "序号",
          width: "60",
        },
        {
          field: "fsxmc",
          title: "事项名称",
          width: "350",
        },
        {
          field: "fqymc",
          title: "企业名称",
          width: "200",
        },
        {
          field: "fjclx",
          title: "审评类型",
          width: "150",
        },
        {
          field: "fslbh",
          title: "受理编号",
          width: "150",
        },
        {
          field: "fcyjssj",
          title: "查验结束时间",
          width: "150",
        },
        {
          field: "fcykssj",
          title: "查验开始时间",
          width: "150",
        },
        {
          field: "frckpjg",
          title: "日常考评结果",
          width: "150",
        },

        {
          title: "操作",
          width: 200,
          field: "operate",
          slots: { default: "operate", fixed: "right" },
          fixed: "right"
        },
      ],
      queryParams: {},
      config: {},
      data: [],
      allAlign: null,
      formData: {
        fsxmc: "",
        fqymc: "",
        fjclx: "",
        fslbh: "",
        frckpjg: "",
      },
      fromItem: [
        {
          field: "fsxmc",
          title: "事项名称",
          type:'input',
          itemRender: {},
        },
        {
          field: "fqymc",
          title: "企业名称",
          type:'input',
          itemRender: {},
        },
        {
          field: "fjclx",
          title: "审评类型",
          type:'input',
          itemRender: {},
        },
        {
          field: "fslbh",
          title: "受理编号",
          type:'input',
          itemRender: {},
        },
        {
          field: "frckpjg",
          title: "日常考评结果",
          type:'input',
          itemRender: {},
        },
      ],
      page: queryRckpStatPageList,
      initialize: {
        fywflcode:'002'
      },
      ajax: {
        list: (sqsxid) => {
          //console.log(sqsxid, "sqsxid================");
          return new Promise((reslove, reject) => {
            queryRckpStatJbxx({ sqsxid: sqsxid })
              .then((res) => {
                reslove(res);
              })
              .catch((error) => {
                reject(res);
              });
          });
        },
      },
    };
  },
  created() {},
  mounted() {},

  methods: {
    checkView(row) {
      this.$refs.modal.handler(row.id);
    },
    // 下载文件
    download() {
      const { query, selectKeysId } = this.$refs.table;
      const formData = new FormData();
      formData.append('fywflcode',this.initialize.fywflcode)
      if (Object.keys(query).length > 0 && selectKeysId.length <= 0) {
        //表单
        for (const key in query) {
          if (Object.hasOwnProperty.call(query, key)) {
            formData.append(`${key}`, query[key]);
          }
        }
        this.dexportRckpJbxxDatas(formData);
      } else if (selectKeysId.length > 0) {
        //表格勾选了
        const strId = selectKeysId.join(",");
        this.dexportRckpJbxxDatas({ ids: strId });
      } else {
        //什么都没有操作，直接下载
      }
    },
    dexportRckpJbxxDatas(data) {
      exportRckpJbxxDatas(data).then((res) => {
        //console.log(res);
        let url = window.URL.createObjectURL(
          new Blob([res], { type: "	application/vnd.ms-excel" })
        );
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "统计.xlsx");
        document.body.appendChild(link);
        link.click();
        window.URL.revokeObjectURL(url);
        document.body.removeChild(link);
      });
    },
  },
};
</script>

<style lang="less" scoped>
// @import "../assets/table.less";
@import url("../assets/table.less");
</style>
